package com.xinqi.modules.prepare.video.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoCreateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoQueryDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoUpdateDTO;
import com.xinqi.modules.prepare.video.dto.rsp.PrepareVideoResultDTO;
import com.xinqi.modules.prepare.video.service.PrepareVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 备课区互动视频APP控制层
 *
 * @author: system
 * @date: 2023/03/19
 */
@Tag(name = "prepare-video-App", description = "备课区互动视频App接口")
//@RestController
@RequestMapping("/app/prepare-video")
@RequiredArgsConstructor
public class PrepareVideoAppController {
    private final PrepareVideoService prepareVideoService;

    /**
     * 备课区互动视频-分页
     */
    @Operation(summary = "备课区互动视频-分页")
    @GetMapping("/page")
    public R<PageInfo<PrepareVideoResultDTO>> page(@ParameterObject PrepareVideoQueryDTO dto) {
        PageInfo<PrepareVideoResultDTO> page = prepareVideoService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 备课区互动视频-详情
     */
    @Operation(summary = "备课区互动视频-详情")
    @GetMapping("/{id}")
    public R<PrepareVideoResultDTO> findById(@PathVariable("id") Long id) {
        PrepareVideoResultDTO dto = prepareVideoService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增备课区互动视频
     */
    @Operation(summary = "新增备课区互动视频")
    @PostMapping
    public R<Long> insert(@RequestBody PrepareVideoCreateDTO dto) {
        return R.data(prepareVideoService.insert(dto));
    }

    /**
     * 修改备课区互动视频
     */
    @Operation(summary = "修改备课区互动视频")
    @PutMapping("/{id}")
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody PrepareVideoUpdateDTO dto) {
        dto.setId(id);
        return R.data(prepareVideoService.updateById(dto));
    }

    /**
     * 删除备课区互动视频
     */
    @Operation(summary = "删除备课区互动视频")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.data(prepareVideoService.deleteById(id));
    }

}
